<?php

namespace app\model;

//use support\Model;
use support\Db;
use Illuminate\Database\Eloquent\Model;

class WaOrdersQuotationAmountDetail
{
    /**
     * The table associated with the model.
     *
     * @var string
     */
    protected $table = 'wa_orders_quotation_order_amount_detail';

    /**
     * The primary key associated with the table.
     *
     * @var string
     */
    protected $primaryKey = 'id';

    /**
     * Indicates if the model should be timestamped.
     *
     * @var bool
     */
    public $timestamps = false;

    public static function all($condition)
    {

        $list = Db::table('wa_orders_quotation_order_amount_detail')
            ->select('*')
            ->where($condition)
            ->orderBy('id', 'asc')
            ->get();

        if ($list) {

        }
        return json_encode($list);

    }



    public static function created($data)
    {
        $result = Db::table('wa_orders_quotation_order_amount_detail')->insertGetId($data);
        return $result;
    }

    public static function updated($data, $where)
    {
        $result = Db::table('wa_orders_quotation_order_amount_detail')->where($where)->update($data);
        return $result;
    }

    public static function deleted($where)
    {
        $result = Db::table('wa_orders_quotation_order_amount_detail')->where($where)->delete();
        return $result;
    }

    public static function list($page, $pageNum, $whereIn,$fields = ['*'], $condition = [], $between = [], $conditions = [])
    {

        $offset = ($page - 1) * $pageNum;
        if ($between) {
            $model = Db::table('wa_orders_quotation_order_amount_detail')
                ->select($fields)
                ->where($condition)
                ->where($conditions)
                ->whereIn('admin_id',$whereIn)
                ->whereBetween('created_at', $between);
        } else {
            $model = Db::table('wa_orders_quotation_order_amount_detail')
                ->select($fields)
                ->where($condition)
                ->where($conditions)
                ->whereIn('admin_id',$whereIn);
        }

        $count = $model->where($condition)->where($conditions)->count();
        $list = $model
            ->orderBy('id', 'desc')
            ->offset($offset)
            ->limit($pageNum)
            ->get();
//        ->paginate($pageNum);

        if ($list) {
        }
        return json_encode(['list' => $list, 'count' => $count]);


    }

    public static function find($condition)
    {
        $res = Db::table('wa_orders_quotation_order_amount_detail')
            ->where($condition)
            ->first();
        return json_encode($res);
    }




}